<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <!-- 搜索框 -->
    <el-input placeholder="请输入内容" v-model.trim="message.query">
      <el-button
        slot="append"
        icon="el-icon-search"
        @click="getSome"
      ></el-button>
    </el-input>
    <div class="table-container">
      <el-table :data="ListData" border style="width: 100%" height="600">
        <el-table-column type="index" width="50"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="180">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180">
        </el-table-column>
        <!-- 付款插槽 -->
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款
            </el-tag>
            <el-tag type="danger" v-else>未付款 </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column
          prop="create_time"
          :formatter="dateFormat"
          label="下单时间"
          width="180"
        ></el-table-column>
      </el-table>
    </div>
    <!-- 分页器区域 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="message.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="message.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ListData: [],
      //分页器信息
      message: {
        pagesize: 5,
        query: '',
        pagenum: 1,
      },
      total: 0,
    }
  },
  //发起接口请求
  created() {
    this.getSome()
  },
  methods: {
    //请求获取页数和当前页
    getSome() {
      this.$http({
        url: '/orders',
        method: 'get',
        params: {
          pagenum: this.message.pagenum,
          pagesize: this.message.pagesize,
          query: this.message.query,
        },
      }).then((res) => {
        this.total = res.data.data.total
        this.ListData = res.data.data.goods
        console.log(res)
      }).catch(err=>{
        console.log(err);
      })
    },

    handleSizeChange(newsize) {
      this.message.pagesize = newsize
      this.getSome()
    },
    handleCurrentChange(newpage) {
      this.message.pagenum = newpage
      this.getSome()
    },
    //格式化时间
    dateFormat(row, column) {
      let time = row[column.property]
      const dt = new Date(time * 1000)
      const y = dt.getFullYear()
      const m = (dt.getMonth() + 1 + '').padStart(2, '0')
      const d = (dt.getDate() + '').padStart(2, '0')
      const hh = (dt.getHours() + '').padStart(2, '0')
      const mm = (dt.getMinutes() + '').padStart(2, '0')
      const ss = (dt.getSeconds() + '').padStart(2, '0')
      return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
    },
  },
}
</script>

<style lang="less" scoped>
.table-container {
  overflow: auto; /* 添加滚动条 */
}
.el-input {
  width: 404px;
}
</style>
